<template>
  <view id="box">
    <GoodList
      :data="list"
      :keys="'id'"
      mainTitleValue="effectList"
      bgimg="pic"
      iconimg="/static/icon/aixin.png"
      viceTitleValue="name"
      moneyValue="price"
      :pageView="true"
      shoppingNum="sale"
      viewNum="look"
      moneySymbol="￥"
      @navTo="navTo"
    />
  </view>
</template>

<script>
  import GoodList from '@/commponents/public/goodsList'
  import goods from '@/services/goods'
  import collect from '@/services/collect'
  import url from '../../common/util/url'
  export default {
    data() {
      return {
        list: [],
        page: 1,
        limit: 10
      }
    },
    components: {
      GoodList
    },
    mounted() {
      // this.list = []
      this.getData()
    },
    onShareAppMessage() {
      let path = '/pages/productDetails/index?id=' + this.params.id
      if (uni.getStorageSync('userId')) {
        path = path + '&userId=' + uni.getStorageSync('userId')
      }
      return {
        title: '我在这里发现了一个好玩的，快来看看',
        path,
        imageUrl: '',
        desc: '描述',
        content: '内容'
      }
    },
    // 滑动到最下面了
    onReachBottom() {
      this.page++
      this.getData()
    },
    methods: {
      getData(boo) {
        let params = url.getCurrentPageParam()
        if (params.from === 'collect') {
          this.getCollectList()
        } else if (params.from === 'lookList') {
          this.getLookList()
        } else {
          // if (boo) {
          //   this.page = 1
          // }
          this.getList()
        }
      },
      getCollectList() {
        collect
          .list({
            page: this.page,
            limit: this.limit
          })
          .then(data => {
            if (data.list.length == 0) {
              this.page--
            }
            this.list.push(...data.list)
          })
      },
      getLookList() {
        goods
          .lookList({
            page: this.page,
            limit: this.limit
          })
          .then(data => {
            if (data.list.length == 0) {
              this.page--
            }
            this.list.push(...data.list)
          })
      },
      getList() {
        let params = url.getCurrentPageParam()
        let obj = {}
        for (let key in params) {
          obj[key] = params[key]
        }
        goods
          .list({
            page: this.page,
            limit: this.limit,
            ...obj
          })
          .then(data => {
            if (data.list.length == 0) {
              this.page--
            }
            this.list.push(...data.list)
          })
      },
      navTo(data) {
        wx.navigateTo({
          url: `/pages/productDetails/index?id=${data}`
        })
      }
    }
  }
</script>

<style lang="scss">
  #box {
    padding: 30rpx 20rpx 10rpx;
  }
</style>
